package com.icbc.open.chengdu.demo.settlement.transfer;

import com.csii.pp.icbc.util.Util;
import com.icbc.api.DefaultIcbcClient;
import com.icbc.api.internal.util.internal.util.fastjson.JSON;
import com.icbc.api.request.SettlementAccountOrientedTransferRequestV1;
import com.icbc.api.response.SettlementAccountOrientedTransferResponseV1;
import com.icbc.open.chengdu.demo.BaseData;
import com.icbc.open.chengdu.demo.utils.GenerateKeyUtils;
import com.icbc.open.chengdu.demo.utils.SecretUtils;

/**
 * 定向转账
 * 支持内部户/往来户与2/3类账户互转
 *
 * @author xcz
 */
public class SettlementAccountOrientedTransferTest {

    public static void main(String[] args) throws Exception {
        String sm4Key =  GenerateKeyUtils.generateSM4Key();//生成SM4密钥
        DefaultIcbcClient client = new DefaultIcbcClient(BaseData.APP_ID, BaseData.MY_RSA_PRIVATE_KEY, BaseData.ICBC_RSA_PUBLIC_KEY);
        SettlementAccountOrientedTransferRequestV1 request = new SettlementAccountOrientedTransferRequestV1();
        SettlementAccountOrientedTransferRequestV1.SettlementAccountOrientedTransferRequestV1Biz bizContent = new SettlementAccountOrientedTransferRequestV1.SettlementAccountOrientedTransferRequestV1Biz();
        request.setServiceUrl(BaseData.ACCOUNT_ORIENTED_TRANSFER_URL);//API地址
        bizContent.setCorpNo(BaseData.APP_ID); //合作方机构编号
        bizContent.setTrxAccDate(BaseData.TEST_TRX_ACC_DATE); //合作方交易日期
        bizContent.setTrxAccTime(BaseData.TEST_TRX_ACC_TIME); //合作方交易时间
        bizContent.setCorpDate(BaseData.TEST_CORP_DATE); //合作方工作日期
        bizContent.setCorpSerno(Util.getNonceStr(16)); //合作方交易单号
        bizContent.setOutServiceCode("orientedtransfer"); //外部服务代码
        bizContent.setMediumId(SecretUtils.encryptSM4(sm4Key, BaseData.TEST_ACCOUNT_NUMBER_2)); //我行卡号
        bizContent.setCcy(1); //币种
        bizContent.setCashExFlag(0); //钞汇标志
        bizContent.setAmount("10000"); //交易金额
        bizContent.setOaccno(SecretUtils.encryptSM4(sm4Key, BaseData.TEST_OACC_NO));//对手账户
        bizContent.setDrcrdirection(1);//借贷方向
        bizContent.setSummary("DY"); //摘要
        bizContent.setRemarks("DY"); //注释
        bizContent.setSecretKey(SecretUtils.encryptSM2(sm4Key));//加密密钥
        bizContent.setCertNo(SecretUtils.encryptSM4(sm4Key, BaseData.TEST_CERT_NO));//证件号码
        bizContent.setCertType(0);//证件类型
        bizContent.setCustName(SecretUtils.encryptSM4(sm4Key, BaseData.TEST_CUS_NAME));//用户名
        request.setBizContent(bizContent);
        SettlementAccountOrientedTransferResponseV1 response = client.execute(request);
        System.out.println(JSON.toJSONString(response));
        if (response.isSuccess()) {
            //成功
        } else {
        }

    }
}
